package prototype;

import com.alibaba.fastjson.JSONObject;
import com.sun.org.apache.bcel.internal.generic.JsrInstruction;
import lombok.Data;

import java.util.List;
/**
 * 原型模式用于对象拷贝 jdk原生拷贝需覆写
 * 对象拷贝分为浅拷贝和深拷贝，浅拷贝仅复制基本数据类型，对引用数据类型仅拷贝引用地址
 * 
 * @author lenovo
 *
 */
@Data
public class ConcretePrototypeA implements Prototype,Cloneable {
	private int age;
	private String name;
	private List hobbies;
	@Override
	public Prototype bb() {
		// TODO Auto-generated method stub
//		ConcretePrototypeA concretePrototypeA=new ConcretePrototypeA();
//		try {
//			concretePrototypeA=(ConcretePrototypeA) this.clone();
//		} catch (CloneNotSupportedException e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		}
		ConcretePrototypeA concretePrototypeA= JSONObject.parseObject(JSONObject.toJSONString(this),ConcretePrototypeA.class);
		return concretePrototypeA;
	}

}
